package com.yy.controller.admin;

import com.yy.controller.service.OrderService;
import com.yy.dto.OrderPageQueryDTO;
import com.yy.entity.Orders;
import com.yy.result.PageResult;
import com.yy.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "订单管理接口")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/list")
    @CrossOrigin
    @ApiOperation("分页条件查询订单列表")
    public Result<PageResult> list(OrderPageQueryDTO orderPageQueryDTO){
        log.info("orderPageQueryDTO:{}",orderPageQueryDTO);
       PageResult pageResult=orderService.list(orderPageQueryDTO);
       return  Result.success(pageResult);
    }
    @GetMapping("/allOrder")
    @CrossOrigin
    @ApiOperation("查询所有订单列表")
    public Result AllOrder(){
        List<Orders> ordersList=orderService.AllOrder();
        return  Result.success(ordersList);
    }
    @PostMapping("/updateStatus/{id}/{cancelReason}")
    @CrossOrigin
    @ApiOperation("修改订单状态(若为取消,添加取消原因)")
    public Result updateStatus(@PathVariable("id") Long id,@PathVariable("cancelReason") String cancelReason){
        orderService.updateStatus(id,cancelReason);
        return  Result.success();
    }
}
